// 路由鉴权，项目当中路由能不能
import router from "./router";
import nprogress from 'nprogress'
import "nprogress/nprogress.css"
import userStore from './store/modules/user'
import setting from './setting'
nprogress.configure({ showSpinner: false });
// 全局前置守卫
router.beforeEach((to:any,from:any,next:any) => {
   console.log(to);
   
   document.title = `${setting.title} - ${to.meta.title}`
   nprogress.start()
   let user = userStore()
   console.log(user.token);
   if(user.token){
      console.log(11111);
      
      if(to.path == '/weixin') {
         next({path: '/home'})
       }else {
         next()
       }
   }else {
      if(to.path == '/weixin') {
        next()
      }else {
        next({path:'/weixin',query:{redirect: to.path}})
      }
   }
})

// 全局后置守卫
router.afterEach((to:any, from:any) => {
   nprogress.done()
 
})